home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Mania 6
/
MacMania 6.toast
/
/
Multimedia & Desktop
/
VideoToolbox
/
VideoToolboxSources
/
MaximizeConsoleHeight.c
< prev
next >
Wrap
Text File
|
1997-04-10
|
5KB
|
116 lines
/*
MaximizeConsoleHeight.c
Both THINK C and Metrowerks CodeWarrior C provide a built-in console for stdin
and stdout. That console is less useful than it might be because it opens to
only a small size, presumably designed to fit on the tiny screen of a Mac Plus,
i.e. the lowest common denominator, for portability. MaximizeConsoleHeight
requests that the console open to the full height of your main screen. This
makes good use of your screen, while maintaining the portability of your
application. Call MaximizeConsoleHeight() BEFORE opening the console, i.e.
before your first printf().
To set the WIDTH of the THINK C console, before opening it, do this:
#include <console.h>
...
console_options.ncols=100;
To set the width of the CodeWarrior console, before opening it, do this:
#include <SIOUX.h>
...
tSIOUXSettings.columns=100;
Incidentally, VideoToolbox.h includes both THINK C's console.h and CodeWarrior's SIOUX.h,
so you can omit the #include statements if you're already including VideoToolbox.h.
LIMITATION:
In June 1994 Mike Garver reported that on a Mac Plus running System 6.07 with an
attached big screen the console window appears on the Mac Plus screen, as it
should, but extends well past the bottom, "so I could see none of the text
unless I moved the window onto the large screen." This happens because, when
Color QuickDraw is not available, MaximizeConsoleHeight() resorts to using the
CrsrPin rect to estimate the height of the main screen. (CrsrPin is the
rectangle to which the cursor is confined. When the desktop isn't rectangular
CrsrPin is the smallest rectangle that contains the desktop.) I don't know how
to fix this. If Color QuickDraw were running then the program would have
correctly gotten the bounds of the main device, but the computer lacks Color
QuickDraw, so there are no video device records, nor a GrayRgn structure to
consult. Since MaximizeConsoleHeight() is typically called before QuickDraw is
initialized we can't use qd.screenBits.bounds (which is probably the same as
CrsrPin rect anyway). I can't think of any way for this program to find out the
correct height of the main screen under these circumstances. So I blame this on
the necessary cludge implicit in having two screens in a computer lacking Color
QuickDraw, since 1-bit QuickDraw doesn't really support multiple screens. I
believe, but didn't confirm, that System 7 provides 32-bit QuickDraw (which
includes Color QuickDraw) on all computers.
HISTORY:
1/92 dgp wrote it.
8/27/92 dgp check for 8-bit quickdraw before using GDevices.
10/10/92 dgp Reduced maximum console height by one pixel, so as not to clip
displayed text.
2/22/93 dgp replaced GetMBarHeight() by MBarHeight.
4/16/93 dgp enhanced to actively support 1-bit QD, rather than doing nothing.
6/3/94 dgp replaced low-memory global MBarHeight by GetMBarHeight().
6/21/94 dgp documented limitation above.
6/28/94 dgp use gdRect instead of pixmap bounds, which is correct for any device,
not just the main device.
10/10/94 dgp added support for Metrowerks CodeWarrior C.
11/17/94 dgp Eliminated need for THINK C's LoMem.h by defining LMGetCrsrPin().
1/7/95 dgp updated to CW5, so that it now works similarly for both THINK & CW C.
4/10/97 dgp Eliminate stuff that was conditional on !UNIVERSAL_HEADERS.
*/
#include "VideoToolbox.h"
#include <LowMem.h> // LMGetMBarHeight,LMSetMBarHeight
// NOTE: Apple's Universal Headers fail to provide any access to CrsrPin, so I rolled my own.
#define LMGetCrsrPin() (* (Rect *) 0x834)
void MaximizeConsoleHeight(void)
{
long qD;
Rect r;
Gestalt(gestaltQuickdrawVersion,&qD);
if(qD>=gestalt8BitQD) r=(*GetMainDevice())->gdRect;
else r=LMGetCrsrPin(); // Can't use qd.screenBits.bounds 'cause qd may not yet be inited.
#if (THINK_C || THINK_CPLUS || SYMANTEC_C)
console_options.top=LMGetMBarHeight()+19; // allow for menu bar and title bar
console_options.left=1;
console_options.nrows=r.bottom-4-console_options.top;
console_options.nrows/=console_options.txSize*4/3-1; /* estimate line spacing */
#endif
#if __MWERKS__
SIOUXSettings.toppixel=LMGetMBarHeight()+19; // allow for menu bar and title bar
SIOUXSettings.leftpixel=1;
SIOUXSettings.rows=r.bottom-4-SIOUXSettings.toppixel;
SIOUXSettings.rows/=SIOUXSettings.fontsize*4/3-1; /* estimate line spacing */
// These settings approximate the behavior of the THINK C console.
SIOUXSettings.autocloseonquit=0;
SIOUXSettings.showstatusline=0;
SIOUXSettings.asktosaveonclose=0;
#endif
#if 0 && __MWERKS__
/*
This code probably fails under CW 5.5. The GetPort returns a window pointer
presumably corresponding to the console,
but subsequent attempts to use that window pointer crash, e.g. in SetWTitle.
I reported the bug to Metrowerks.
*/
Rect r;
GDHandle device;
WindowPtr window;
printf("\n");
GetPort(&window);
device=GetWindowDevice(window);
if(device==NULL)return;
r=(**device).gdRect;
if(GetMainDevice()==device)r.top+=LMGetMBarHeight();
r.top+=19; // allow for title bar
r.bottom-=1; // allow for 1-pixel frame
r.left+=1; // allow for 1-pixel frame
if(r.right-r.left>500)r.right=r.left+500;
// SizeWindow(window,r.right-r.left,r.bottom-r.top,1);
MoveWindow(window,r.left,r.top,1);
#endif
}